package jacidco;

import java.awt.Toolkit;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

public class ActualizaDatosFrame extends javax.swing.JFrame
{
    int cod;
    static String rutaFoto="";
    JFileChooser choser;
    ImageIcon im;
    Toolkit t;
    URL imagenURL;
    
    public ActualizaDatosFrame()
    {
        initComponents();
        
        choser = new JFileChooser();
        getRootPane().setDefaultButton(btnBuscar);
        fillComboBox();
        
    }
    
    static void setRutaFoto(String ruta)
    {
        rutaFoto = ruta;
    }
    
    static public String getRutaFoto()
    {
        return rutaFoto;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblTitulo1 = new javax.swing.JLabel();
        btnNuevo = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        lblNumeroAfiliado = new javax.swing.JLabel();
        txtNumeroAfiliado = new javax.swing.JTextField();
        lblPrimerApellido = new javax.swing.JLabel();
        txtPrimerNombre = new javax.swing.JTextField();
        lblPrimerNombre = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtPrimerApellido = new javax.swing.JTextField();
        txtCedula = new javax.swing.JTextField();
        lblSegundoNombre = new javax.swing.JLabel();
        txtSegundoApellido = new javax.swing.JTextField();
        lblSegundoApellido = new javax.swing.JLabel();
        txtSegundoNombre = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtCodigoJava = new javax.swing.JTextField();
        btnBuscar = new javax.swing.JButton();
        cmbMes = new javax.swing.JComboBox();
        cmbAno = new javax.swing.JComboBox();
        cmbDia = new javax.swing.JComboBox();
        btnVolver = new javax.swing.JButton();
        btnActualizar = new javax.swing.JButton();
        lblMarcareg = new javax.swing.JLabel();
        lblTitulo = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        lblInstitucion = new javax.swing.JLabel();
        txtInstitucion = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        lblCarrera = new javax.swing.JLabel();
        txtCarrera = new javax.swing.JTextField();
        lblTelefonos = new javax.swing.JLabel();
        lblEmail = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtEmpresa = new javax.swing.JTextField();
        cmbNivel = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        txtTelCasa = new javax.swing.JTextField();
        txtTelOficina = new javax.swing.JTextField();
        txtTelCelular = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        lblOficina = new javax.swing.JLabel();
        lblCelular = new javax.swing.JLabel();
        btnFoto = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        lblFotoAlumno = new javax.swing.JLabel();
        btnEliminar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Actualizacion de Datos");
        setResizable(false);

        lblTitulo1.setFont(new java.awt.Font("Times New Roman", 3, 36));
        lblTitulo1.setText("Actualizacion de Datos");
        lblTitulo1.setName("lblTitulo1"); // NOI18N

        btnNuevo.setFont(new java.awt.Font("Tahoma", 3, 11));
        btnNuevo.setText("Nuevo");
        btnNuevo.setName("btnNuevo"); // NOI18N
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });

        jLabel1.setBackground(new java.awt.Color(255, 51, 51));
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jacidco/resources/Logo_Jacidco_mini.png"))); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel1.setName("jPanel1"); // NOI18N

        lblNumeroAfiliado.setFont(new java.awt.Font("Tahoma", 2, 11));
        lblNumeroAfiliado.setText("No. Afiliado : ");
        lblNumeroAfiliado.setName("lblNumeroAfiliado"); // NOI18N

        txtNumeroAfiliado.setName("txtNumeroAfiliado"); // NOI18N

        lblPrimerApellido.setFont(new java.awt.Font("Tahoma", 2, 11));
        lblPrimerApellido.setText("Primer Apellido : ");
        lblPrimerApellido.setName("lblPrimerApellido"); // NOI18N

        txtPrimerNombre.setName("txtPrimerNombre"); // NOI18N

        lblPrimerNombre.setFont(new java.awt.Font("Tahoma", 2, 11));
        lblPrimerNombre.setText("Primer Nombre : ");
        lblPrimerNombre.setName("lblPrimerNombre"); // NOI18N

        jLabel6.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel6.setText("Cedula : ");
        jLabel6.setName("jLabel6"); // NOI18N

        txtPrimerApellido.setName("txtPrimerApellido"); // NOI18N

        txtCedula.setName("txtCedula"); // NOI18N

        lblSegundoNombre.setFont(new java.awt.Font("Tahoma", 2, 11));
        lblSegundoNombre.setText("Segundo Nombre : ");
        lblSegundoNombre.setName("lblSegundoNombre"); // NOI18N

        txtSegundoApellido.setName("txtSegundoApellido"); // NOI18N

        lblSegundoApellido.setFont(new java.awt.Font("Tahoma", 2, 11));
        lblSegundoApellido.setText("Segundo Apellido : ");
        lblSegundoApellido.setName("lblSegundoApellido"); // NOI18N

        txtSegundoNombre.setName("txtSegundoNombre"); // NOI18N

        jLabel7.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel7.setText("Fecha Nacimiento : ");
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel10.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel10.setText("Codigo :");
        jLabel10.setName("jLabel10"); // NOI18N

        txtCodigoJava.setName("txtCodigoJava"); // NOI18N

        btnBuscar.setText("Buscar");
        btnBuscar.setName("btnBuscar"); // NOI18N
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        cmbMes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));
        cmbMes.setName("cmbMes"); // NOI18N

        cmbAno.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1960", "1961", "1962", "1963", "1964", "1965", "1966", "1967", "1968", "1969", "1970", "1971", "1972", "1973", "1974", "1975", "1976", "1977", "1978", "1979", "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005" }));
        cmbAno.setName("cmbAno"); // NOI18N

        cmbDia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        cmbDia.setName("cmbDia"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblPrimerApellido)
                    .addComponent(lblNumeroAfiliado)
                    .addComponent(lblPrimerNombre)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtPrimerNombre, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtCedula, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                    .addComponent(txtPrimerApellido)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(txtNumeroAfiliado, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnBuscar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(lblSegundoNombre)
                        .addComponent(lblSegundoApellido)
                        .addComponent(jLabel7))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(54, 54, 54)
                        .addComponent(jLabel10)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(txtCodigoJava, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(txtSegundoApellido, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE)
                        .addComponent(txtSegundoNombre, javax.swing.GroupLayout.Alignment.LEADING))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(cmbDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(97, 97, 97))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(txtCodigoJava, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txtSegundoNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblSegundoNombre))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel7)
                                    .addComponent(cmbDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(cmbMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(cmbAno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(txtSegundoApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblSegundoApellido))
                                .addGap(76, 76, 76))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNumeroAfiliado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblNumeroAfiliado)
                            .addComponent(btnBuscar))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPrimerApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblPrimerApellido))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPrimerNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblPrimerNombre))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))))
                .addContainerGap(35, Short.MAX_VALUE))
        );

        btnVolver.setFont(new java.awt.Font("Tahoma", 3, 11));
        btnVolver.setText("Volver");
        btnVolver.setName("btnVolver"); // NOI18N
        btnVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVolverActionPerformed(evt);
            }
        });

        btnActualizar.setFont(new java.awt.Font("Tahoma", 3, 11));
        btnActualizar.setText("Actualizar");
        btnActualizar.setName("btnActualizar"); // NOI18N
        btnActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnActualizarActionPerformed(evt);
            }
        });

        lblMarcareg.setFont(new java.awt.Font("Times New Roman", 0, 11));
        lblMarcareg.setText("Copyright 2011. DCM. All Rights Reserved");
        lblMarcareg.setName("lblMarcareg"); // NOI18N

        lblTitulo.setFont(new java.awt.Font("Times New Roman", 3, 24));
        lblTitulo.setText("Comunidad Dinamica en Java");
        lblTitulo.setName("lblTitulo"); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel2.setName("jPanel2"); // NOI18N

        lblInstitucion.setFont(new java.awt.Font("Tahoma", 2, 11));
        lblInstitucion.setText("Institucion  : ");
        lblInstitucion.setName("lblInstitucion"); // NOI18N

        txtInstitucion.setName("txtInstitucion"); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jLabel3.setText("Dir. Residencia : ");
        jLabel3.setName("jLabel3"); // NOI18N

        txtDireccion.setName("txtDireccion"); // NOI18N

        lblCarrera.setFont(new java.awt.Font("Tahoma", 2, 11));
        lblCarrera.setText("Carrera : ");
        lblCarrera.setName("lblCarrera"); // NOI18N

        txtCarrera.setName("txtCarrera"); // NOI18N

        lblTelefonos.setFont(new java.awt.Font("Tahoma", 2, 11));
        lblTelefonos.setText("Telefonos : ");
        lblTelefonos.setName("lblTelefonos"); // NOI18N

        lblEmail.setFont(new java.awt.Font("Tahoma", 2, 11));
        lblEmail.setText("     Email : ");
        lblEmail.setName("lblEmail"); // NOI18N

        txtEmail.setName("txtEmail"); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel5.setText("Empresa :");
        jLabel5.setName("jLabel5"); // NOI18N

        txtEmpresa.setName("txtEmpresa"); // NOI18N

        cmbNivel.setName("cmbNivel"); // NOI18N

        jLabel8.setText("Nivel : ");
        jLabel8.setName("jLabel8"); // NOI18N

        jPanel3.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel3.setName("jPanel3"); // NOI18N

        txtTelCasa.setName("txtTelCasa"); // NOI18N

        txtTelOficina.setName("txtTelOficina"); // NOI18N

        txtTelCelular.setName("txtTelCelular"); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel4.setText("Casa : ");
        jLabel4.setName("jLabel4"); // NOI18N

        lblOficina.setFont(new java.awt.Font("Tahoma", 2, 11));
        lblOficina.setText("Oficina : ");
        lblOficina.setName("lblOficina"); // NOI18N

        lblCelular.setFont(new java.awt.Font("Tahoma", 2, 11));
        lblCelular.setText("Celular : ");
        lblCelular.setName("lblCelular"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(lblOficina)
                    .addComponent(lblCelular))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(txtTelCelular, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtTelOficina, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtTelCasa, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTelCasa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTelOficina, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblOficina))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTelCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCelular))
                .addContainerGap())
        );

        btnFoto.setFont(new java.awt.Font("Tahoma", 2, 11));
        btnFoto.setText("Actualizar Foto");
        btnFoto.setName("btnFoto"); // NOI18N
        btnFoto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFotoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblEmail)
                    .addComponent(lblInstitucion)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                    .addComponent(cmbNivel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                    .addComponent(txtEmpresa, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                    .addComponent(txtInstitucion, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblCarrera)
                    .addComponent(lblTelefonos))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtCarrera, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                    .addComponent(btnFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(99, 99, 99))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtCarrera, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblCarrera))
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addComponent(lblTelefonos))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnFoto))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtInstitucion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblInstitucion))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblEmail))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cmbNivel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanel4.setName("jPanel4"); // NOI18N

        lblFotoAlumno.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jacidco/resources/foto.jpg"))); // NOI18N
        lblFotoAlumno.setName("lblFotoAlumno"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblFotoAlumno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblFotoAlumno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        btnEliminar.setFont(new java.awt.Font("Tahoma", 3, 11));
        btnEliminar.setText("Eliminar");
        btnEliminar.setName("btnEliminar"); // NOI18N
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lblTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblTitulo1, javax.swing.GroupLayout.DEFAULT_SIZE, 445, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 97, Short.MAX_VALUE)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblMarcareg)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 228, Short.MAX_VALUE)
                                .addComponent(btnNuevo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnActualizar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnEliminar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnVolver))
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(51, 51, 51))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblTitulo)
                        .addGap(67, 67, 67)
                        .addComponent(lblTitulo1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblMarcareg)
                    .addComponent(btnVolver)
                    .addComponent(btnEliminar)
                    .addComponent(btnActualizar)
                    .addComponent(btnNuevo))
                .addGap(40, 40, 40))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed

        txtPrimerNombre.setText("");
        txtSegundoNombre.setText("");
        txtPrimerApellido.setText("");
        txtSegundoApellido.setText("");
        txtCedula.setText("");

        txtCarrera.setText("");
        txtInstitucion.setText("");
        txtDireccion.setText("");
        txtTelCasa.setText("");
        txtTelOficina.setText("");
        txtTelCelular.setText("");
        txtEmail.setText("");
        txtEmpresa.setText("");
        txtNumeroAfiliado.setText("");
        txtNumeroAfiliado.setEnabled(true);
        txtCodigoJava.setText("");

    }//GEN-LAST:event_btnNuevoActionPerformed

    private void btnVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVolverActionPerformed

        Main.goToMenuPrincipal();
        dispose();

    }//GEN-LAST:event_btnVolverActionPerformed

    private void btnActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActualizarActionPerformed
        
        Main.afiliado.setCod(Integer.parseInt(txtNumeroAfiliado.getText()));
        Main.afiliado.setprimerNombre(txtPrimerNombre.getText());
        Main.afiliado.setsegundoNombre(txtSegundoNombre.getText());
        Main.afiliado.setprimerApellido(txtPrimerApellido.getText());
        Main.afiliado.setsegundoApellido(txtSegundoApellido.getText());
        Main.afiliado.setCedula(Integer.parseInt(txtCedula.getText()));
        
        Main.afiliado.setCarrera(txtCarrera.getText());
        Main.afiliado.setInstituto(txtInstitucion.getText());
        Main.afiliado.setDireccion(txtDireccion.getText());
        Main.afiliado.setTelCasa(Integer.parseInt(txtTelCasa.getText()));
        Main.afiliado.setTelOfi(Integer.parseInt(txtTelOficina.getText()));
        Main.afiliado.setTelCel(Long.parseLong(txtTelCelular.getText()));
        Main.afiliado.setMail(txtEmail.getText());
        Main.afiliado.setEmpresa(txtEmpresa.getText());
        Main.afiliado.setCodJava(txtCodigoJava.getText());
        Main.afiliado.setCodNivel((cmbNivel.getSelectedIndex()+1));
        Main.afiliado.setFoto(getRutaFoto());
        
        Main.afiliado.setDia(cmbDia.getItemAt(cmbDia.getSelectedIndex()).toString());
        Main.afiliado.setMes(cmbMes.getItemAt(cmbMes.getSelectedIndex()).toString());
        Main.afiliado.setAno(cmbAno.getItemAt(cmbAno.getSelectedIndex()).toString());
        
        Main.bd.conectar();
        
        if(Main.bd.actualizaDatos(Main.afiliado.getCodJava(), Main.afiliado.getprimerApellido(), Main.afiliado.getsegundoApellido(), Main.afiliado.getprimerNombre(), Main.afiliado.getsegundoNombre(), 
                Main.afiliado.getCedula(), Main.afiliado.getInstituto(), Main.afiliado.getCarrera(), Main.afiliado.getDireccion(), Main.afiliado.getTelCasa(), 
                Main.afiliado.getTelOfi(), Main.afiliado.getTelCel(), Main.afiliado.getEmpresa(), Main.afiliado.getMail(), Main.afiliado.getCodNivel(), Main.afiliado.getFoto(),Main.afiliado.getCod()))
        {
            JOptionPane.showMessageDialog(null, "Datos Actualizados Correctamente", "Actualizacion", JOptionPane.INFORMATION_MESSAGE);
        }
        
        actualizaNacimiento();
        
        Main.bd.cerrarConexion();
        
    }//GEN-LAST:event_btnActualizarActionPerformed

    private void btnFotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFotoActionPerformed

        int returnVal = choser.showOpenDialog(ActualizaDatosFrame.this);
         
         if (returnVal == JFileChooser.APPROVE_OPTION) 
         {
             File f = choser.getSelectedFile();
             setRutaFoto(choser.getCurrentDirectory().toURI().toString()+choser.getName(f));
         }

    }//GEN-LAST:event_btnFotoActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed

        ResultSet rs;
        cod = Integer.parseInt(txtNumeroAfiliado.getText());

        Main.bd.conectar();
        rs = Main.bd.buscaAfiliado(cod);

        try
        {
            if(rs.next())
            {
                txtPrimerApellido.setText(rs.getString("primer_apellido"));
                txtSegundoApellido.setText(rs.getString("segundo_apellido"));
                txtPrimerNombre.setText(rs.getString("primer_nombre"));
                txtSegundoNombre.setText(rs.getString("segundo_nombre"));
                txtCedula.setText(rs.getString("cedula"));

                txtInstitucion.setText(rs.getString("institucion"));
                txtCarrera.setText(rs.getString("carrera"));
                txtDireccion.setText(rs.getString("direccion"));
                txtTelCasa.setText(rs.getString("telefono_casa"));
                txtTelOficina.setText(rs.getString("telefono_ofi"));
                txtTelCelular.setText(rs.getString("telefono_cel"));
                txtEmpresa.setText(rs.getString("empresa"));
                txtEmail.setText(rs.getString("mail"));
                txtCodigoJava.setText(rs.getString("cod_java"));
                cmbNivel.setSelectedIndex(Main.bd.selectNivelActualizar(cod)-1);
                txtNumeroAfiliado.setEnabled(false);  
                setRutaFoto(rs.getString("foto"));
            }
            else
            {
                JOptionPane.showMessageDialog(null, "Alumno no existe", "Informacion", JOptionPane.ERROR_MESSAGE);
            }
        }
        catch (SQLException ex)
        {
            Logger.getLogger(ActualizaDatosFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
        /* Despliega la foto del alumno en el formulario */
        if(!getRutaFoto().isEmpty())
        {
            try 
            {
                imagenURL = new URL(getRutaFoto());
            } 
            catch (MalformedURLException ex) 
            {
                JOptionPane.showMessageDialog(null, "Error al Cargar la Foto\n\nDetalles\n\n"+ex, "Error", JOptionPane.ERROR_MESSAGE);
            }

            im = new ImageIcon(imagenURL);
            lblFotoAlumno.setIcon(im);
        }
        Main.bd.cerrarConexion();

    }//GEN-LAST:event_btnBuscarActionPerformed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        
        int codAf = Integer.parseInt(txtNumeroAfiliado.getText());
        Main.bd.conectar();

        Main.bd.delete(codAf);
            
        Main.bd.cerrarConexion();
        
    }//GEN-LAST:event_btnEliminarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnActualizar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnFoto;
    private javax.swing.JButton btnNuevo;
    private javax.swing.JButton btnVolver;
    private javax.swing.JComboBox cmbAno;
    private javax.swing.JComboBox cmbDia;
    private javax.swing.JComboBox cmbMes;
    private javax.swing.JComboBox cmbNivel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JLabel lblCarrera;
    private javax.swing.JLabel lblCelular;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblFotoAlumno;
    private javax.swing.JLabel lblInstitucion;
    private javax.swing.JLabel lblMarcareg;
    private javax.swing.JLabel lblNumeroAfiliado;
    private javax.swing.JLabel lblOficina;
    private javax.swing.JLabel lblPrimerApellido;
    private javax.swing.JLabel lblPrimerNombre;
    private javax.swing.JLabel lblSegundoApellido;
    private javax.swing.JLabel lblSegundoNombre;
    private javax.swing.JLabel lblTelefonos;
    private javax.swing.JLabel lblTitulo;
    private javax.swing.JLabel lblTitulo1;
    private javax.swing.JTextField txtCarrera;
    private javax.swing.JTextField txtCedula;
    private javax.swing.JTextField txtCodigoJava;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtEmpresa;
    private javax.swing.JTextField txtInstitucion;
    private javax.swing.JTextField txtNumeroAfiliado;
    private javax.swing.JTextField txtPrimerApellido;
    private javax.swing.JTextField txtPrimerNombre;
    private javax.swing.JTextField txtSegundoApellido;
    private javax.swing.JTextField txtSegundoNombre;
    private javax.swing.JTextField txtTelCasa;
    private javax.swing.JTextField txtTelCelular;
    private javax.swing.JTextField txtTelOficina;
    // End of variables declaration//GEN-END:variables
    
    /**
     * Llena el Combo Box con los nombres de los niveles disponibles
     */
    public void fillComboBox()
    {
         Main.bd.conectar();
        int cap = Main.bd.nextCode("cod_nivel","nivel")+1;

        Vector nombre = new Vector(cap);
        Vector nombre2 = new Vector(cap);

        nombre2 = Main.bd.muestraDatosComboBoxes(nombre,"nivel");

        for(int i=1;i<cap;i++)
        {
            cmbNivel.addItem(nombre2.get(i));
        }

        Main.bd.cerrarConexion();
    }
    
    /**
     * 
     */
    public void actualizaNacimiento()
    {
        Main.bd.conectar();
        if(Main.bd.actualizaFechaNacimiento(Main.afiliado.getCod(), Main.afiliado.getDia(), Main.afiliado.getMes(), Main.afiliado.getAno()))
        {
                    
        }
        else{}
        
        Main.bd.cerrarConexion();
    }
}
